package com.shtel.bss.saas.core.data.common.entiry.repository;

import com.shtel.bss.saas.core.base.spring.ApplicationContextUtil;
import com.shtel.bss.saas.core.data.common.entiry.IBaseEntity;
import java.io.Serializable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.util.StringUtils;

/**
 * @author xiezhiwei
 * @version Revision 1.0
 * @版权： 版权所有 (c) 2018
 * @创建日期： 2020/2/4 15:18
 * @功能说明：
 */
public class RepositoryFactory {

	private static final Logger LOG = LoggerFactory.getLogger(RepositoryFactory.class);

	public static <T extends IBaseEntity<ID>, ID extends Serializable> IBaseRepository getRepository(Class<? extends IBaseEntity> clazz) {
		IBaseRepository<T> rep = null;
		String repositoryName = StringUtils.uncapitalize(clazz.getSimpleName() + "Repository");

		try {
			rep = (IBaseRepository) ApplicationContextUtil.getBean(repositoryName);
			return rep;
		} catch (BeansException var4) {
			LOG.debug("Spring上下文中未配置仓库：" + repositoryName);
//			rep = getDefaultRepository(c);
//			return rep;
		}
		return rep;
	}
}
